package com.hmall.search.interceptor;

import com.hmall.search.context.BaseContext;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * Feign拦截器,添加请求头
 */
@Component
@Slf4j
public class MyFeignInterceptor implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate template) {
        log.info("===request: {}", template.url());
        //获取请求头
       /* ServletRequestAttributes servletRequestAttributes=(ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        if (servletRequestAttributes!=null){
            HttpServletRequest request = servletRequestAttributes.getRequest();
            if (request!=null){
                request.getHeader("authorization");
            }
        }*/
        //添加请求头
        template.header("authorization", BaseContext.getAuthorization());
        template.header("userId", BaseContext.getCurrentId());
    }
}
